<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of wallet_model
 *
 * @author win7
 */
class wallet_bank_model extends cms_model {

    //put your code here
    public function __construct() {
        parent::__construct();
        $this->table = 'wallet_bank';
    }

    public function filter($limit = FALSE, $order = FALSE) {
        $config['total_rows'] = $this->get(array('user_id' => $this->user_id), TRUE);
        if ($limit)
            $config['per_page'] = $limit;
        else
            $config['per_page'] = 30;
        if (!$order || $order == 'up') {
            $this->order = array('id' => 'desc');
        } else {
            $this->order = array('id' => 'asc');
        }
        $data['result'] = $this->get(array('user_id' => $this->user_id), FALSE, 'result', $config['per_page']);
        //$data['pagination'] = $this->cms_pagination($url = 'index', $config['total_rows'], $config['per_page']);
        return $data;
    }

    /*public function save($data) {
        // insert into wallte
        $this->db->insert('wallet', array('user_id' => $this->user_id,
            'user_add' => $this->user_id,
            'create_date' => $data['create_date'],
            'operation' => 'plus',
            'amount' => $data['amount'],
            'note' => lang('message_wallet_note_add_account'),
            'status' => $data['status']
        ));
        $id = $this->db->insert_id();
        // insert information wallet_bank
    }*/

    function aftersave($id) {
        $this->db->insert('wallet_bank', array(
            'wallet_id' => $id,
            'bank_name' => $this->data['bank_name'],
            'sender_name' => $this->data['sender_name'],
            'account_number' => $this->data['account_number'],
            'note' => $this->data['note'],
        ));
    }

    /*public function withdraw($data) {
        // insert into wallte
        $this->db->insert('wallet', array('user_id' => $this->user_id,
            'user_add' => $this->user_id,
            'create_date' => $data['create_date'],
            'operation' => 'minus',
            'amount' => $data['amount'],
            'note' => lang('message_wallet_note_withdraw_account'),
            'status' => $data['status']
        ));
        $id = $this->db->insert_id();
        // insert information wallet_bank
        $this->db->insert('wallet_bank', array('wallet_id' => $id,
            'bank_name' => $data['bank_name'],
            'account_number' => $data['account_number'],
            'sender_name' => $data['sender_name'],
            'note' => $data['note'],
        ));
    }

    public function add($data) {

        $this->db->insert('wallet', array('user_id' => $this->user_id,
            'user_add' => $this->user_id,
            'create_date' => date('Y-m-d H:i:s'),
            'operation' => 'minus',
            'amount' => $data['cashe']['Total'],
            'note' => sprintf(lang('message_wallet_add_bill_'), $data['bill_id']),
            'status' => 'pending'
        ));
        $id = $this->db->insert_id();
        $this->db->update('order_invoices', array('wallet' => $id, 'addressbook_id' => $data['addressbook'], 'user_update' => $this->user_id, 'paid' => 'YES', 'payment_date' => date('Y-m-d H:i:s'), 'cash' => $data['cashe']['Total'], 'coupone_id' => $data['coupone_id'], 'coupone_discount' => $data['coupone_discount'], 'trans_com' => $data['trans_com']), array('id' => $data['bill_id']));
        // coupone used
        $this->db->insert('coupons_used', array('user_id' => $this->user_id, 'coupon_id' => $data['coupone_id'], 'create_date' => date('Y-m-d H:i:s')));
        // copune used
        $this->db->update('coupons', array('used' => 'YES'), array('id' => $data['coupone_id']));
        // invoice 
        $this->db->insert('invoices_histroy', array('user_id' => $this->user_id, 'invoice_id' => $data['bill_id'], 'operation' => 'payment', 'create_date' => date('Y-m-d H:i:s')));
    }
*/
}

?>
